package com.medusa.aps.business.modules.board.model.input;

import com.medusa.aps.business.model.pagination.Page;
import com.medusa.aps.business.global.model.o.RangeDate;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.experimental.Accessors;

import java.time.LocalDate;
import java.util.Set;

/**
 * <p>封装车间排产统计查询参数</p>
 * @author An.Yan
 */
@Data
@Accessors(chain = true)
@Schema(description = "车间排产统计查询参数")
public class WorkshopProductionStatisticsParam extends Page<WorkshopProductionStatisticsParam> {

    /**
     * 日期范围
     */
    @Schema(description = "日期范围")
    private RangeDate dateRange = new RangeDate();

    /**
     * 车间编码
     */
    @Schema(description = "车间编码")
    private String workshopCode;

    /**
     * 车间名称
     */
    @Schema(description = "车间名称")
    private String workshopName;

    /**
     * 要导出的数据的ID集合
     */
    @Schema(description = "要导出的数据的ID集合")
    private Set<Long> ids;

    public void validateParam() {
        LocalDate now = LocalDate.now();
        if (this.getDateRange().getStart() == null && this.getDateRange().getEnd() == null) {
            this.dateRange.setStart(now);
            this.dateRange.setEnd(now.plusDays(30));
            return;
        }
        if (this.getDateRange().getStart() != null && this.getDateRange().getEnd() == null) {
            this.dateRange.setEnd(this.getDateRange().getStart().plusDays(30));
            return;
        }
        if (this.getDateRange().getStart() == null && this.getDateRange().getEnd() != null) {
            this.dateRange.setStart(this.getDateRange().getEnd().minusDays(30));
            return;
        }

    }

}
